package fr.aquariophilie.org;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class userdb {

	public int id;
	public String user;
	public String password;
	
	public userdb(){}
	
	public userdb(String user, String password){
		final String pw = md5(password);
		this.password = pw;
		this.user = user;
	}
	
	public int getId(){
		return id;
	}
	
	public String getUser(){
		return user;
	}
	
	public void setUser(String user){
		this.user = user;
	}
	
	public void setPassword(String password){
		final String pw = md5(password);
		this.password = pw;
	}
	
	public void setId(int id){
		this.id = id;
	}
	
	public String getPassword(){
		return password;
	}
	
	public String md5(String in)
	{
		MessageDigest digest;
		
		try
		{
			digest = MessageDigest.getInstance("MD5");
			digest.reset();
			digest.update(in.getBytes());
			byte[] a = digest.digest();
			int len = a.length;
			StringBuilder sb = new StringBuilder(len << 1);
			for (int i = 0; i < len; i++)
			{
				sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
				sb.append(Character.forDigit(a[i] & 0x0f, 16));
			}
			return sb.toString();
		}
		catch (NoSuchAlgorithmException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
